<template>
  <div class="app-container">
    <div class="search-container">
      <div class="search-wrap">
        <!-- <div style="display:inline-block;">
          <label class="radio-label" style="padding-left:0;">网络名称: </label>
          <el-input v-model="fieldName" placeholder="" style="width:240px;"/>
        </div>

        <div style="display:inline-block;">
          <label class="radio-label">网段: </label>
          <el-input v-model="fieldName" placeholder="" style="width:240px;"/>
        </div>
        <el-button :loading="downloadLoading" style="margin:0 0 20px 20px;" type="primary" icon="el-icon-search">
          搜索
        </el-button>
        <el-button :loading="downloadLoading" style="margin:0 0 20px 20px;" type="info" icon="el-icon-refresh-right">
          重置
        </el-button> -->
      </div>

      <div class="btn-wrap radio-label">
        <el-button :loading="downloadLoading" style="margin:0 0 20px 20px;" type="primary" icon="el-icon-circle-plus-outline"
        @click="dialogTableVisible = true">
          新增
        </el-button>
      </div>
    </div>

    <el-table v-loading="listLoading" :data="list" element-loading-text="Loading..." fit highlight-current-row>
      <el-table-column align="center" label="编号" width="95">
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="真实主机IP" >
        <template slot-scope="scope">
          {{ scope.row.name }}
        </template>
      </el-table-column>
      <el-table-column label="伪装IP(绑定数量)" width="200">
        <template slot-scope="scope">
          {{ scope.row.text }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="路径跳数"  width="150">
        <template slot-scope="scope">
          {{ scope.row.number }}
        </template>
      </el-table-column> -->
      <el-table-column label="协议"  width="150">
        <template slot-scope="scope">
          {{ scope.row.protocol }}
        </template>
      </el-table-column>
      <el-table-column label="跳变时间"  width="150">
        <template slot-scope="scope">
          {{ scope.row.number }}
        </template>
      </el-table-column>
      <el-table-column label="范围"  width="150">
        <template slot-scope="scope">
          {{ scope.row.range }}%
        </template>
      </el-table-column>

      <el-table-column label="操作" width="320" align="center">
        <template slot-scope="{row}">
          <el-button
            type="success"
            size="mini"
            icon="el-icon-s-operation"
            @click="dialogListVisible = true"
          >
            伪装IP列表
          </el-button>

          <el-button
                type="warning"
                size="mini"
                icon="el-icon-edit"
              >
                修改
              </el-button>

          <el-button
            type="danger"
            size="mini"
            icon="el-icon-delete"
          >
            删除
          </el-button>
        </template>
        
      </el-table-column>
    </el-table>

    <div class="pagination">
      <el-pagination
        background
        layout="prev, pager, next"
        :total="1000">
      </el-pagination>
    </div>


    <el-dialog v-el-drag-dialog :visible.sync="dialogTableVisible" title="新增网络混淆" @dragDialog="handleDrag" width="1200px">
      <el-form ref="dataForm" :rules="rules" :model="temp" label-position="right" label-width="120px">
        <el-row>
          <el-col :span="24">
            <div class="form-title">网关配置</div>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="主机列表" prop="title">
              <el-select v-model="temp.host" class="filter-item" placeholder="请选择主机">
                <el-option v-for="item in hostOptions" :key="item" :label="item" :value="item" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="伪装IP列表" prop="title">
              <el-select v-model="temp.ip" class="filter-item" multiple placeholder="请选择伪装IP">
                <el-option v-for="item in ipOptions" :key="item" :label="item" :value="item" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="混淆协议" prop="title">
              <el-select v-model="temp.protocol" class="filter-item" size="medium" placeholder="请选择混淆协议" clearable filterable allow-create>
                <el-option v-for="item in protocolOptions" :key="item" :label="item" :value="item" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <div class="form-title">混淆策略</div>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="跳变时间(分钟)" prop="title">
              <el-select v-model="temp.date" class="filter-item" size="medium" placeholder="请选择时间" clearable filterable allow-create>
                <el-option v-for="item in dateOptions" :key="item" :label="item" :value="item" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="范围" prop="title">
              <el-input value="50">
                <template slot="append">%</template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogTableVisible = false">
          取消
        </el-button>
        <el-button type="primary" @click="dialogTableVisible = false">
          确认
        </el-button>
      </div>
    </el-dialog>


    <el-dialog v-el-drag-dialog :visible.sync="dialogListVisible" title="伪装IP列表" width="1200px">
      <el-form ref="dataForm" :rules="rules" :model="temp" label-position="right" label-width="120px">
        <el-row>
          <el-col :span="24">
            <div class="form-item">
              <div class="title">真实主机IP</div>
              <div class="content">
                <el-input value="192.168.10.128" disabled ></el-input>
              </div>
            </div>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <div class="form-list-title">伪装IP列表</div>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-input
              type="textarea"
              :rows="8"
              v-model="ipListText">
            </el-input>
          </el-col>
        </el-row>

      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { fetchList } from '@/api/article'

import Pagination from '@/components/Pagination'
import elDragDialog from '@/directive/el-drag-dialog'

export default {
  name: 'Confuse',
  components: { Pagination },
  directives: { elDragDialog },
  data() {
    return {
      list: null,
      fieldName: '',
      ipListText: '192.168.10.166;12.28.10.114;52.78.110.36;14.68.101.67;121.14.110.15;18.12.110.64;74.26.30.45;48.69.11.46;15.18.8.69;17.85.23.36',
      listLoading: true,
      downloadLoading: false,
      autoWidth: true,


      formList: [
        {
          ip: '192.168.2.118,192.168.2.118,192.168.2.118,192.168.2.118,192.168.2.118...',
          server: 'SSH蜜罐,FTP蜜罐,MAIL蜜罐,SMB蜜罐...',
          status: '运行中'
        },
        {
          ip: '203.45.12.85,225,234.142.118,18.10.2.88...',
          server: '天融信上网行为管理系统蜜罐,天融信防火墙蜜罐,深信服WAF系统蜜罐,奇安信防火墙系统蜜罐...',
          status: '运行中'
        },
      ],
      dialogTableVisible: false,
      dialogListVisible: false,

      rules: {
        type: [{ required: true, message: 'type is required', trigger: 'change' }],
        timestamp: [{ type: 'date', required: true, message: 'timestamp is required', trigger: 'change' }],
        title: [{ required: true, message: 'title is required', trigger: 'blur' }]
      },
      temp: {
        id: undefined,
        importance: 1,
        remark: '',
        timestamp: new Date(),
        title: '',
        type: '',
        status: 'published',
        outEth: ['eth0'],
        inEth: 'eth1',
        netType: '静态网络',
        protocol: ''
      },
      hostOptions: ['28.12.125.74','47.45.109.68','12.16.84.57','176.86.94.57','175.116.180.77','112.116.110.107','182.16.10.8','2.16.105.57','182.161.122.77'],
      ipOptions: ['172.16.10.2', '172.16.10.3','172.16.10.4', '172.16.10.5','172.16.10.6', '172.16.10.7','172.16.10.8','172.16.10.9','172.16.10.10'],
      protocolOptions: ['PING','WEB'],
      dateOptions: ['1','5','10','30','90']
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      let data = []
      fetchList().then(response => {
        data.push({
          name: "198.15.28.41",
          text: "12",
          number: 10,
          level: '高',
          protocol: 'tcp',
          range: 40
        })
        data.push({
          name: "114.66.58.112",
          text: "15",
          number: 10,
          level: '低',
          protocol: 'tcp',
          range: 77
        })
        data.push({
          name: "45.66.68.44",
          text: "16",
          number: 10,
          level: '高',
          protocol: 'udp',
          range: 20
        })
        this.list = data
        this.listLoading = false
      })
    },
    handleDrag() {
      console.log("添加页面")
    }
  }
}
</script>

<style scoped>
.radio-label {
  font-size: 14px;
  color: #606266;
  line-height: 40px;
  padding: 0 12px 0 30px;
}
.pagination {
  margin-top: 20px;
  display: flex;
  justify-content: right;
}
.search-container {
  display: flex;
  justify-content: space-between;
}
.search-wrap {
  flex: 1;
}

.form-title {
  margin-bottom: 10px;
  padding-bottom: 10px;
  display: flex;
  align-items: center;
  font-size: 14px;
  font-weight: bold;
  border-bottom: 1px solid #F1F1F1;
  box-sizing: border-box;
}

.form-list-title {
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  font-size: 14px;
  font-weight: bold;
}

.el-select {
  width: 100%;
}


.desc-item {
  margin-bottom: 20px;
}

.el-dialog__body {
  padding: 10px 20px;
}

.form-item { 
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  width: 100%;
}

.form-item .title {
  padding: 10px 0;
  display: flex;
  align-items: center;
  font-size: 14px;
  font-weight: bold;
}

.form-item .content {
  flex: 1;
  margin-left: 10px;
}
</style>